package team.seekers.hula.island.postComment.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import team.seekers.hula.common.annotation.ApiResponseBody;
import team.seekers.hula.common.entity.UserSessionDTO;
import team.seekers.hula.island.postComment.entity.dto.*;
import team.seekers.hula.island.postComment.entity.vo.PostCommentReplyListVO;
import team.seekers.hula.island.postComment.service.IslandPostCommentReplyService;
import team.seekers.hula.island.postComment.service.IslandPostCommentService;
import team.seekers.hula.auth.service.MindUtils;

import java.util.List;

/**
 * @author ekin
 * @Description GOOD
 * @mood happy
 */
@Controller
@ApiResponseBody
@RequestMapping("/post/comment/reply")
public class PostCommentReplyController {

    @Autowired
    private IslandPostCommentService islandPostCommentService;

    @Autowired
    private IslandPostCommentReplyService islandPostCommentReplyService;


    /**
     * 评论回复
     */
    @PostMapping("/create")
    public PostCommentReplyListVO replyComment(@RequestBody PostCommentReplyDTO postCommentDTO) {
        UserSessionDTO userSessionDTO = MindUtils.getUser();
        postCommentDTO.setUserId(userSessionDTO.getId());
        postCommentDTO.setNickname(userSessionDTO.getNickname());
        return islandPostCommentService.replyComment(postCommentDTO);
    }

    /**
     * 给回复点赞或取消点赞
     */
    @GetMapping("/like-or-cancel")
    public void likeOrCancel(@RequestParam String replyId) {
        islandPostCommentReplyService.likeOrCancel(replyId, MindUtils.getUserId());
    }

    /**
     * 评论列表
     */
    @GetMapping("/list")
    public List<PostCommentReplyListVO> listReply(String commentId) {
        return islandPostCommentReplyService.listReply(commentId);
    }
}
